name: CI

on:
  push:
    branches:
      - "main"
    paths:
      - "chatbot/**"
      - "tests/**"
      - ".github/workflows/**"
  pull_request:
    types: [opened, reopened, synchronize, ready_for_review]
    paths:
      - "chatbot/**"
      - "tests/**"
      - ".github/workflows/**"

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install poetry
        uses: snok/install-poetry@v1
        with:
          version: 1.7.0
          virtualenvs-in-project: true
      # Installing torch (CPU) and sentence-transformers with pip to avoid poetry's issues in installing torch.
      # Installing llama-cpp-python without NVIDIA CUDA acceleration.
      - name: Setup environment
        run: |
          poetry lock --check
          poetry install --no-root --no-ansi
          . .venv/bin/activate && pip3 install torch~=2.1.2 torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
          . .venv/bin/activate && pip3 install sentence-transformers~=2.2.2
          . .venv/bin/activate && pip3 install llama-cpp-python~=0.2.23

      - name: Run tests
        run: |
          poetry run python -m pytest --durations=5 --log-cli-level=DEBUG --capture=tee-sys -v
